package tencent

import (
	"bytes"
)

func (Solution1) reverseWords(s string) string {
	result, tmp := "", ""
	for i := 0; i < len(s); i++ {
		if s[i] == ' ' {
			result = result + tmp + string(' ')
			tmp = ""
			continue
		}
		tmp = string(s[i]) + tmp
	}
	return result + tmp
}
func (Solution) reverseWords(s string) string {
	result, tmp := bytes.Buffer{}, ""
	for i := 0; i < len(s); i++ {
		if s[i] == ' ' {
			result.Write([]byte(tmp))
			result.WriteByte(' ')
			tmp = ""
			continue
		}
		tmp = string(s[i]) + tmp
	}
	result.Write([]byte(tmp))
	return result.String()
}

func reverseString(s []byte) {
	//交换的思路做
	left, right := (len(s)-1)/2, len(s)/2
	for left >= 0 {
		tmp := s[left]
		s[left] = s[right]
		s[right] = tmp
		left--
		right++
	}
}
